<html>
<META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<head>
<title>Section 20.9.&nbsp; Performance</title>
<link rel="STYLESHEET" type="text/css" href="images/style.css">
<link rel="STYLESHEET" type="text/css" href="images/docsafari.css">
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr><td><div STYLE="MARGIN-LEFT: 0.15in;"><a href="toc.html"><img src="images/team.gif" width="60" height="17" border="0" align="absmiddle"  alt="Team BBL"></a></div></td>
<td align="right"><div STYLE="MARGIN-LEFT: 0.15in;">
<a href=ch20lev1sec8.html><img src="images/prev.gif" width="60" height="17" border="0" align="absmiddle" alt="Previous Page"></a>
<a href=ch20lev1sec10.html><img src="images/next.gif" width="60" height="17" border="0" align="absmiddle" alt="Next Page"></a>
</div></td></tr></table>
<br><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td valign="top"><a name="ch20lev1sec9"></a>
<h3 class="docSection1Title" id="454331-805">20.9. Performance</h3>
<p class="docText">To test the database library and to obtain some timing measurements of the database access patterns of typical applications, a test program was written. This program takes two command-line arguments: the number of children to create and the number of database records (<span class="docEmphasis">nrec</span>) for each child to write to the database. The program then creates an empty database (by calling <tt>db_open</tt>), <tt>fork</tt>s the number of child processes, and waits for all the children to terminate. Each child performs the following steps.</P>
<div style="font-weight:bold"><ol class="docList" type="1"><LI><div style="font-weight:normal"><p class="docList"><a name="idd1e152457"></a>Write <span class="docEmphasis">nrec</span> records to the database.</p></div></LI><LI><div style="font-weight:normal"><p class="docList">Read the <span class="docEmphasis">nrec</span> records back by key value.</P></div></li><LI><div style="font-weight:normal"><p class="docList">Perform the following loop <span class="docEmphasis">nrec</span> x <span class="docEmphasis">5</span> times.</P><div style="font-weight:bold"><ol class="docList" type="a"><LI><div style="font-weight:normal"><p class="docList">Read a random record.</p></div></LI><li><div style="font-weight:normal"><p class="docList">Every 37 times through the loop, delete a random record.</P></div></LI><LI><div style="font-weight:normal"><p class="docList">Every 11 times through the loop, insert a new record and read the record back.</p></div></LI><LI><div style="font-weight:normal"><p class="docList">Every 17 times through the loop, replace a random record with a new record. Every other one of these replacements is a record with the same size data, and the alternate is a record with a longer data portion.</p></div></LI></ol></div></div></LI><li><div style="font-weight:normal"><p class="docList">Delete all the records that this child wrote. Every time a record is deleted, ten random records are looked up.</p></div></li></ol></div>
<p class="docText">The number of operations performed on the database is counted by the <tt>cnt_xxx</tt> variables in the <tt>DB</tt> structure, which were incremented in the functions. The number of operations differs from one child to the next, since the random-number generator used to select records is initialized in each child to the child's process ID. A typical count of the operations performed in each child, when <span class="docEmphasis">nrec</span> is 500, is shown in <a class="docLink" href="#ch20fig06">Figure 20.6</a>.</p>
<a name="ch20fig06"></a><P><table cellspacing="0" class="allBorders" border="1" RULES="groups" cellpadding="5"><caption><h5 class="docTableTitle">Figure 20.6. Typical count of operations performed by each child when nrec is 500</H5></caption><colgroup><col width="450"><col width="50"></colgroup><thead><tr><th class="rightBorder bottomBorder thead" scope="col" align="center" valign="top"><p class="docText"><span class="docEmphRoman">Operation</span></P></th><th class="bottomBorder thead" scope="col" align="right" valign="top"><p class="docText"><span class="docEmphRoman">Count</span></p></th></tr></thead><tr><td class="rightBorder" align="left" valign="top"><p class="docText"><tt>db_store</tt>, <tt>DB_INSERT</tt>, no empty record, appended</p></td><td class="docTableCell" align="right" valign="top"><p class="docText">678</p></td></tr><tr><td class="rightBorder" align="left" valign="top"><p class="docText"><tt>db_store</tt>, <tt>DB_INSERT</tt>, empty record reused</p></td><td class="docTableCell" align="right" valign="top"><p class="docText">164</p></td></TR><TR><td class="rightBorder" align="left" valign="top"><p class="docText"><tt>db_store</tt>, <tt>DB_REPLACE</tt>, different data length, appended</P></TD><TD class="docTableCell" align="right" valign="top"><p class="docText">97</p></TD></TR><TR><td class="rightBorder" align="left" valign="top"><p class="docText"><tt>db_store</tt>, <tt>DB_REPLACE</tt>, equal data length</P></td><TD class="docTableCell" align="right" valign="top"><p class="docText">109</P></TD></tr><TR><TD class="rightBorder bottomBorder" align="left" valign="top"><p class="docText"><tt>db_store</tt>, record not found</p></TD><TD class="bottomBorder" align="right" valign="top"><p class="docText">19</p></td></tr><tr><TD class="rightBorder" align="left" valign="top"><p class="docText"><tt>db_fetch</tt>, record found</p></TD><td class="docTableCell" align="right" valign="top"><p class="docText">8,114</P></td></tr><tr><td class="rightBorder bottomBorder" align="left" valign="top"><p class="docText"><tt>db_fetch</tt>, record not found</p></td><td class="bottomBorder" align="right" valign="top"><p class="docText">732</p></td></tr><tr><td class="rightBorder" align="left" valign="top"><p class="docText"><tt>db_delete</tt>, record found</p></td><td class="docTableCell" align="right" valign="top"><p class="docText">842</p></td></TR><TR><td class="rightBorder" align="left" valign="top"><p class="docText"><tt>db_delete</tt>, record not found</P></TD><TD class="docTableCell" align="right" valign="top"><p class="docText">110</p></TD></TR></table></P><br>
<p class="docText">We performed about ten times more fetches than stores or deletions, which is probably typical of many database applications.</P>
<p class="docText">Each child is doing these operations (fetching, storing, and deleting) only with the records that the child wrote. The concurrency controls are being exercised because all the children are operating on the same database (albeit different records in the same database). The total number of records in the database increases in proportion to the number of children. (With one child, <span class="docEmphasis">nrec</span> records are originally written to the database. With two children, <span class="docEmphasis">nrec</span> x <span class="docEmphasis">2</span> records are originally written, and so on.)</p>
<p class="docText">To test the concurrency provided by coarse-grained locking versus fine-grained locking and to compare the three types of locking (no locking, advisory locking, and mandatory locking), we ran three versions of the test program. The first version used the source code shown in <a class="docLink" href="ch20lev1sec8.html#ch20lev1sec8">Section 20.8</a>, which we've called fine-grained locking. The <a name="idd1e152715"></a><a name="idd1e152720"></a><a name="idd1e152723"></a>second version changed the locking calls to implement coarse-grained locking, as described in <a class="docLink" href="ch20lev1sec6.html#ch20lev1sec6">Section 20.6</a>. The third version had all locking calls removed, so we could measure the overhead involved in locking. We can run the first and second versions (fine-grained locking and coarse-grained locking) using either advisory or mandatory locking, by changing the permission bits on the database files. (In all the tests reported in this section, we measured the times for mandatory locking using only the implementation of fine-grained locking.)</P>
<p class="docText">All the timing tests in this section were done on a SPARC system running Solaris 9.</P>
<a name="ch20lev2sec3"></a>
<H4 class="docSection2Title">Single-Process Results</h4>
<p class="docText"><a class="docLink" href="#ch20fig07">Figure 20.7</a> shows the results when only a single child process ran, with an <span class="docEmphasis">nrec</span> of 500, 1,000, and 2,000.</P>
<a name="ch20fig07"></a><P><table cellspacing="0" class="allBorders" border="1" RULES="groups" cellpadding="5"><caption><h5 class="docTableTitle">Figure 20.7. Single child, varying <span class="docEmphasis">nrec</span>, different locking techniques</H5></caption><colgroup><col width="20"><col width="40"><col width="40"><col width="40"><col width="40"><col width="40"><col width="40"><col width="40"><col width="40"><col width="40"><col width="40"><col width="40"><col width="40"></colgroup><thead><TR><th class="rightBorder bottomBorder thead" scope="col" align="center" valign="bottom" rowspan="3"><p class="docText"><span class="docEmphRoman"><span class="docEmphasis">nrec</span></span></p></th><th class="rightBorder bottomBorder thead" scope="col" align="center" valign="top" rowspan="2" colspan="3"><p class="docText"><span class="docEmphRoman">No locking</span></p></th><th class="rightBorder bottomBorder thead" scope="col" align="center" valign="top" colspan="6"><p class="docText"><span class="docEmphRoman">Advisory locking</span></p></th><th class="bottomBorder thead" scope="col" align="center" valign="top" colspan="3"><p class="docText"><span class="docEmphRoman">Mandatory locking</span></p></th></TR><tr><th class="rightBorder bottomBorder thead" scope="col" align="center" valign="top" colspan="3"><p class="docText"><span class="docEmphRoman">Coarse-grained locking</span></P></th><th class="rightBorder bottomBorder thead" scope="col" align="center" valign="bottom" colspan="3"><p class="docText"><span class="docEmphRoman">Fine-grained locking</span></p></th><th class="bottomBorder thead" scope="col" align="center" valign="bottom" colspan="3"><p class="docText"><span class="docEmphRoman">Fine-grained locking</span></P></th></tr><tr><th class="rightBorder bottomBorder thead" scope="col" align="center" valign="top"><p class="docText"><span class="docEmphRoman">User</span></p></th><th class="rightBorder bottomBorder thead" scope="col" align="center" valign="top"><p class="docText"><span class="docEmphRoman">Sys</span></p></th><th class="rightBorder bottomBorder thead" scope="col" align="center" valign="top"><p class="docText"><span class="docEmphRoman">Clock</span></p></th><th class="rightBorder bottomBorder thead" scope="col" align="center" valign="top"><p class="docText"><span class="docEmphRoman">User</span></p></th><th class="rightBorder bottomBorder thead" scope="col" align="center" valign="top"><p class="docText"><span class="docEmphRoman">Sys</span></p></th><th class="rightBorder bottomBorder thead" scope="col" align="center" valign="top"><p class="docText"><span class="docEmphRoman">Clock</span></p></th><th class="rightBorder bottomBorder thead" scope="col" align="center" valign="top"><p class="docText"><span class="docEmphRoman">User</span></p></th><th class="rightBorder bottomBorder thead" scope="col" align="center" valign="top"><p class="docText"><span class="docEmphRoman">Sys</span></p></th><th class="rightBorder bottomBorder thead" scope="col" align="center" valign="top"><p class="docText"><span class="docEmphRoman">Clock</span></p></th><th class="rightBorder bottomBorder thead" scope="col" align="center" valign="top"><p class="docText"><span class="docEmphRoman">User</span></p></th><th class="rightBorder bottomBorder thead" scope="col" align="center" valign="top"><p class="docText"><span class="docEmphRoman">Sys</span></p></th><th class="bottomBorder thead" scope="col" align="center" valign="top"><p class="docText"><span class="docEmphRoman">Clock</span></p></th></tr></thead><tr><td class="rightBorder" align="center" valign="top"><p class="docText">500</P></TD><td class="rightBorder" align="center" valign="top"><p class="docText">0.42</P></TD><TD class="rightBorder" align="center" valign="top"><p class="docText">0.89</p></TD><TD class="rightBorder" align="center" valign="top"><p class="docText">1.31</P></td><TD class="rightBorder" align="center" valign="top"><p class="docText">0.42</p></TD><TD class="rightBorder" align="center" valign="top"><p class="docText">1.17</P></td><TD class="rightBorder" align="center" valign="top"><p class="docText">1.59</P></td><TD class="rightBorder" align="center" valign="top"><p class="docText">0.41</P></td><td class="rightBorder" align="center" valign="top"><p class="docText">1.04</p></td><TD class="rightBorder" align="center" valign="top"><p class="docText">1.45</p></TD><td class="rightBorder" align="center" valign="top"><p class="docText">0.46</P></td><td class="rightBorder" align="center" valign="top"><p class="docText">1.49</p></td><td class="docTableCell" align="center" valign="top"><p class="docText">1.95</p></td></tr><tr><td class="rightBorder" align="center" valign="top"><p class="docText">1,000</p></td><td class="rightBorder" align="center" valign="top"><p class="docText">1.51</p></td><td class="rightBorder" align="center" valign="top"><p class="docText">3.89</p></TD><TD class="rightBorder" align="center" valign="top"><p class="docText">5.41</p></TD><TD class="rightBorder" align="center" valign="top"><p class="docText">1.64</P></td><TD class="rightBorder" align="center" valign="top"><p class="docText">4.13</P></TD><td class="rightBorder" align="center" valign="top"><p class="docText">5.78</P></td><TD class="rightBorder" align="center" valign="top"><p class="docText">1.63</P></TD><td class="rightBorder" align="center" valign="top"><p class="docText">4.12</P></TD><td class="rightBorder" align="center" valign="top"><p class="docText">5.76</P></TD><td class="rightBorder" align="center" valign="top"><p class="docText">1.73</p></td><td class="rightBorder" align="center" valign="top"><p class="docText">6.34</P></td><TD class="docTableCell" align="center" valign="top"><p class="docText">8.07</p></TD></tr><tr><td class="rightBorder" align="center" valign="top"><p class="docText">2,000</p></td><td class="rightBorder" align="center" valign="top"><p class="docText">3.91</p></td><td class="rightBorder" align="center" valign="top"><p class="docText">10.06</p></td><td class="rightBorder" align="center" valign="top"><p class="docText">13.98</p></td><td class="rightBorder" align="center" valign="top"><p class="docText">4.09</p></td><TD class="rightBorder" align="center" valign="top"><p class="docText">10.30</P></td><TD class="rightBorder" align="center" valign="top"><p class="docText">14.39</P></TD><td class="rightBorder" align="center" valign="top"><p class="docText">4.03</P></TD><TD class="rightBorder" align="center" valign="top"><p class="docText">10.63</p></TD><td class="rightBorder" align="center" valign="top"><p class="docText">14.66</P></TD><TD class="rightBorder" align="center" valign="top"><p class="docText">4.47</p></TD><TD class="rightBorder" align="center" valign="top"><p class="docText">16.21</p></TD><TD class="docTableCell" align="center" valign="top"><p class="docText">20.70</p></td></tr></table></p><BR>
<p class="docText">The last 12 columns give the corresponding times in seconds. In all cases, the user CPU time plus the system CPU time approximately equals the clock time. This set of tests was CPU-limited and not disk-limited.</p>
<p class="docText">The six columns under &quot;Advisory locking&quot; are almost equal for each row. This makes sense because for a single process, there is no difference between coarse-grained locking and fine-grained locking.</P>
<p class="docText">Comparing no locking versus advisory locking, we see that adding the locking calls adds between 2 percent and 31 percent to the system CPU time. Even though the locks are never used (since only a single process is running), the system call overhead in the calls to <tt>fcntl</tt> adds time. Also note that the user CPU time is about the same for all four versions of locking. Since the user code is almost equivalent (except for the number of calls to <tt>fcntl</tt>), this makes sense.</p>
<p class="docText">The final point to note from <a class="docLink" href="#ch20fig07">Figure 20.7</a> is that mandatory locking adds between 43 percent and 54 percent to the system CPU time, compared to advisory locking. Since the number of locking calls is the same for advisory fine-grained locking and mandatory fine-grained locking, the additional system call overhead must be in the reads and writes.</P>
<p class="docText">The final test was to try the no-locking program with multiple children. The results, as expected, were random errors. Normally, records that were added to the database couldn't be found, and the test program aborted. Different errors occurred every time the test program was run. This illustrates a classic race condition: multiple processes updating the same file without using any form of locking.</p>

<a name="ch20lev2sec4"></a>
<h4 class="docSection2Title">Multiple-Process Results</h4>
<p class="docText"><a name="idd1e153091"></a>The next set of measurements looks mainly at the differences between coarse-grained locking and fine-grained locking. As we said earlier, intuitively, we expect fine-grained locking to provide additional concurrency, since there is less time that portions of the database are locked from other processes. <a class="docLink" href="#ch20fig08">Figure 20.8</a> shows the results for an <span class="docEmphasis">nrec</span> of 500, varying the number of children from 1 to 12.</p>
<a name="ch20fig08"></a><p><table cellspacing="0" class="allBorders" border="1" RULES="groups" cellpadding="5"><caption><h5 class="docTableTitle">Figure 20.8. Comparison of various locking techniques, <span class="docEmphasis">nrec</span> = 500</h5></caption><colgroup><col width="50"><col width="50"><col width="40"><col width="40"><col width="40"><col width="40"><col width="40"><col width="40"><col width="40"><col width="40"><col width="40"><col width="40"></colgroup><thead><tr><th class="rightBorder bottomBorder thead" scope="col" align="center" valign="bottom" rowspan="3"><p class="docText"><span class="docEmphRoman">#Proc</span></p></th><th class="rightBorder bottomBorder thead" scope="col" align="center" valign="top" colspan="7"><p class="docText"><span class="docEmphRoman">Advisory locking</span></p></th><th class="bottomBorder thead" scope="col" align="center" valign="top" colspan="4"><p class="docText"><span class="docEmphRoman">Mandatory locking</span></p></th></tr><tr><th class="rightBorder bottomBorder thead" scope="col" align="center" valign="top" colspan="3"><p class="docText"><span class="docEmphRoman">Coarse-grained locking</span></p></th><th class="rightBorder bottomBorder thead" scope="col" align="center" valign="middle" colspan="3"><p class="docText"><span class="docEmphRoman">Fine-grained locking</span></p></th><th class="rightBorder bottomBorder thead" scope="col" align="center" valign="middle"><p class="docText"><span class="docEmphRoman"><font face="symbol">D</font></span></p></th><th class="rightBorder bottomBorder thead" scope="col" align="center" valign="middle" colspan="3"><p class="docText"><span class="docEmphRoman">Fine-grained locking</span></p></th><th class="bottomBorder thead" scope="col" align="center" valign="middle"><p class="docText"><span class="docEmphRoman"><font face="symbol">D</font></span></P></th></TR><tr><th class="rightBorder bottomBorder thead" scope="col" align="center" valign="top"><p class="docText"><span class="docEmphRoman">User</span></P></th><th class="rightBorder bottomBorder thead" scope="col" align="center" valign="top"><p class="docText"><span class="docEmphRoman">Sys</span></P></th><th class="rightBorder bottomBorder thead" scope="col" align="center" valign="top"><p class="docText"><span class="docEmphRoman">Clock</span></P></th><th class="rightBorder bottomBorder thead" scope="col" align="center" valign="top"><p class="docText"><span class="docEmphRoman">User</span></p></th><th class="rightBorder bottomBorder thead" scope="col" align="center" valign="top"><p class="docText"><span class="docEmphRoman">Sys</span></P></th><th class="rightBorder bottomBorder thead" scope="col" align="center" valign="top"><p class="docText"><span class="docEmphRoman">Clock</span></P></th><th class="rightBorder bottomBorder thead" scope="col" align="center" valign="top"><p class="docText"><span class="docEmphRoman">Clock</span></P></th><th class="rightBorder bottomBorder thead" scope="col" align="center" valign="top"><p class="docText"><span class="docEmphRoman">User</span></p></th><th class="rightBorder bottomBorder thead" scope="col" align="center" valign="top"><p class="docText"><span class="docEmphRoman">Sys</span></P></th><th class="rightBorder bottomBorder thead" scope="col" align="center" valign="top"><p class="docText"><span class="docEmphRoman">Clock</span></p></th><th class="bottomBorder thead" scope="col" align="center" valign="top"><p class="docText"><span class="docEmphRoman">Percent</span></P></th></TR></thead><TR><td class="rightBorder" align="center" valign="top"><p class="docText">1</P></TD><td class="rightBorder" align="center" valign="top"><p class="docText">0.41</P></TD><td class="rightBorder" align="center" valign="top"><p class="docText">1.00</p></td><td class="rightBorder" align="center" valign="top"><p class="docText">1.42</P></td><TD class="rightBorder" align="center" valign="top"><p class="docText">0.41</p></TD><td class="rightBorder" align="center" valign="top"><p class="docText">1.05</p></td><td class="rightBorder" align="center" valign="top"><p class="docText">1.47</p></td><td class="rightBorder" align="center" valign="top"><p class="docText">0.05</p></td><td class="rightBorder" align="center" valign="top"><p class="docText">0.47</p></td><td class="rightBorder" align="center" valign="top"><p class="docText">1.40</p></td><td class="rightBorder" align="center" valign="top"><p class="docText">1.87</p></TD><TD class="docTableCell" align="center" valign="top"><p class="docText">33</p></TD></TR><TR><td class="rightBorder" align="center" valign="top"><p class="docText">2</P></TD><TD class="rightBorder" align="center" valign="top"><p class="docText">1.10</p></TD><td class="rightBorder" align="center" valign="top"><p class="docText">2.81</P></TD><TD class="rightBorder" align="center" valign="top"><p class="docText">3.92</p></TD><TD class="rightBorder" align="center" valign="top"><p class="docText">1.11</p></TD><TD class="rightBorder" align="center" valign="top"><p class="docText">2.80</p></td><td class="rightBorder" align="center" valign="top"><p class="docText">3.92</p></TD><td class="rightBorder" align="center" valign="top"><p class="docText">0.00</P></td><TD class="rightBorder" align="center" valign="top"><p class="docText">1.15</p></td><td class="rightBorder" align="center" valign="top"><p class="docText">4.06</p></td><td class="rightBorder" align="center" valign="top"><p class="docText">5.22</p></td><td class="docTableCell" align="center" valign="top"><p class="docText">45</p></td></tr><tr><td class="rightBorder" align="center" valign="top"><p class="docText">3</p></td><td class="rightBorder" align="center" valign="top"><p class="docText">2.17</P></TD><td class="rightBorder" align="center" valign="top"><p class="docText">5.27</P></TD><TD class="rightBorder" align="center" valign="top"><p class="docText">7.44</p></TD><TD class="rightBorder" align="center" valign="top"><p class="docText">2.19</P></td><TD class="rightBorder" align="center" valign="top"><p class="docText">5.18</p></TD><TD class="rightBorder" align="center" valign="top"><p class="docText">7.37</P></td><TD class="rightBorder" align="center" valign="top"><p class="docText">0.07</P></td><TD class="rightBorder" align="center" valign="top"><p class="docText">2.31</P></td><td class="rightBorder" align="center" valign="top"><p class="docText">7.67</p></td><TD class="rightBorder" align="center" valign="top"><p class="docText">9.99</p></TD><td class="docTableCell" align="center" valign="top"><p class="docText">48</P></td></tr><tr><td class="rightBorder" align="center" valign="top"><p class="docText">4</p></td><td class="rightBorder" align="center" valign="top"><p class="docText">3.36</p></td><td class="rightBorder" align="center" valign="top"><p class="docText">8.55</p></td><td class="rightBorder" align="center" valign="top"><p class="docText">11.91</p></td><td class="rightBorder" align="center" valign="top"><p class="docText">3.26</p></TD><TD class="rightBorder" align="center" valign="top"><p class="docText">8.67</p></TD><TD class="rightBorder" align="center" valign="top"><p class="docText">11.94</P></td><TD class="rightBorder" align="center" valign="top"><p class="docText">0.03</P></TD><td class="rightBorder" align="center" valign="top"><p class="docText">3.51</P></td><TD class="rightBorder" align="center" valign="top"><p class="docText">12.69</P></TD><td class="rightBorder" align="center" valign="top"><p class="docText">16.20</P></TD><td class="docTableCell" align="center" valign="top"><p class="docText">46</P></TD></tr><tr><td class="rightBorder" align="center" valign="top"><p class="docText">5</p></TD><td class="rightBorder" align="center" valign="top"><p class="docText">4.72</P></td><TD class="rightBorder" align="center" valign="top"><p class="docText">13.08</p></td><td class="rightBorder" align="center" valign="top"><p class="docText">17.80</p></td><td class="rightBorder" align="center" valign="top"><p class="docText">4.99</p></td><td class="rightBorder" align="center" valign="top"><p class="docText">12.64</p></td><td class="rightBorder" align="center" valign="top"><p class="docText">17.64</p></td><td class="rightBorder" align="center" valign="top"><p class="docText">0.16</p></td><TD class="rightBorder" align="center" valign="top"><p class="docText">4.91</P></td><TD class="rightBorder" align="center" valign="top"><p class="docText">19.21</P></TD><td class="rightBorder" align="center" valign="top"><p class="docText">24.14</P></TD><TD class="docTableCell" align="center" valign="top"><p class="docText">52</p></TD></tr><TR><TD class="rightBorder" align="center" valign="top"><p class="docText">6</P></td><TD class="rightBorder" align="center" valign="top"><p class="docText">6.45</P></td><TD class="rightBorder" align="center" valign="top"><p class="docText">17.96</P></td><td class="rightBorder" align="center" valign="top"><p class="docText">24.42</p></td><TD class="rightBorder" align="center" valign="top"><p class="docText">6.83</p></TD><td class="rightBorder" align="center" valign="top"><p class="docText">17.29</P></td><td class="rightBorder" align="center" valign="top"><p class="docText">24.14</p></td><td class="rightBorder" align="center" valign="top"><p class="docText">0.28</p></td><td class="rightBorder" align="center" valign="top"><p class="docText">7.03</p></td><td class="rightBorder" align="center" valign="top"><p class="docText">26.59</p></td><td class="rightBorder" align="center" valign="top"><p class="docText">33.66</p></td><td class="docTableCell" align="center" valign="top"><p class="docText">54</P></TD></tr><TR><TD class="rightBorder" align="center" valign="top"><p class="docText">7</P></td><TD class="rightBorder" align="center" valign="top"><p class="docText">8.46</P></TD><td class="rightBorder" align="center" valign="top"><p class="docText">23.12</P></td><TD class="rightBorder" align="center" valign="top"><p class="docText">31.62</P></TD><td class="rightBorder" align="center" valign="top"><p class="docText">8.67</P></TD><td class="rightBorder" align="center" valign="top"><p class="docText">22.96</P></TD><td class="rightBorder" align="center" valign="top"><p class="docText">31.65</p></td><td class="rightBorder" align="center" valign="top"><p class="docText">0.03</P></td><TD class="rightBorder" align="center" valign="top"><p class="docText">9.25</p></TD><td class="rightBorder" align="center" valign="top"><p class="docText">35.47</p></td><td class="rightBorder" align="center" valign="top"><p class="docText">44.74</p></td><td class="docTableCell" align="center" valign="top"><p class="docText">54</p></td></tr><tr><td class="rightBorder" align="center" valign="top"><p class="docText">8</p></td><td class="rightBorder" align="center" valign="top"><p class="docText">10.83</p></td><TD class="rightBorder" align="center" valign="top"><p class="docText">29.68</P></td><TD class="rightBorder" align="center" valign="top"><p class="docText">40.55</P></TD><td class="rightBorder" align="center" valign="top"><p class="docText">11.00</P></TD><TD class="rightBorder" align="center" valign="top"><p class="docText">29.39</p></TD><td class="rightBorder" align="center" valign="top"><p class="docText">40.41</P></TD><TD class="rightBorder" align="center" valign="top"><p class="docText">0.14</p></TD><TD class="rightBorder" align="center" valign="top"><p class="docText">11.67</p></TD><TD class="rightBorder" align="center" valign="top"><p class="docText">45.90</p></td><td class="rightBorder" align="center" valign="top"><p class="docText">57.63</p></TD><td class="docTableCell" align="center" valign="top"><p class="docText">56</P></td></TR><tr><td class="rightBorder" align="center" valign="top"><p class="docText">9</p></td><td class="rightBorder" align="center" valign="top"><p class="docText">13.35</p></td><td class="rightBorder" align="center" valign="top"><p class="docText">36.81</p></td><td class="rightBorder" align="center" valign="top"><p class="docText">50.23</p></td><td class="rightBorder" align="center" valign="top"><p class="docText">13.43</p></td><td class="rightBorder" align="center" valign="top"><p class="docText">36.28</P></TD><td class="rightBorder" align="center" valign="top"><p class="docText">49.76</P></TD><TD class="rightBorder" align="center" valign="top"><p class="docText">0.47</p></TD><TD class="rightBorder" align="center" valign="top"><p class="docText">14.45</P></td><TD class="rightBorder" align="center" valign="top"><p class="docText">58.02</p></TD><TD class="rightBorder" align="center" valign="top"><p class="docText">72.49</P></td><TD class="docTableCell" align="center" valign="top"><p class="docText">60</P></td></TR><TR><td class="rightBorder" align="center" valign="top"><p class="docText">10</p></td><td class="rightBorder" align="center" valign="top"><p class="docText">16.35</P></td><TD class="rightBorder" align="center" valign="top"><p class="docText">45.28</p></TD><td class="rightBorder" align="center" valign="top"><p class="docText">61.66</p></td><td class="rightBorder" align="center" valign="top"><p class="docText">16.09</p></td><td class="rightBorder" align="center" valign="top"><p class="docText">44.10</p></td><td class="rightBorder" align="center" valign="top"><p class="docText">60.23</p></td><td class="rightBorder" align="center" valign="top"><p class="docText">1.43</p></td><td class="rightBorder" align="center" valign="top"><p class="docText">17.43</p></TD><TD class="rightBorder" align="center" valign="top"><p class="docText">70.90</p></TD><TD class="rightBorder" align="center" valign="top"><p class="docText">88.37</P></td><TD class="docTableCell" align="center" valign="top"><p class="docText">61</P></TD></tr><TR><td class="rightBorder" align="center" valign="top"><p class="docText">11</P></TD><TD class="rightBorder" align="center" valign="top"><p class="docText">18.97</p></TD><TD class="rightBorder" align="center" valign="top"><p class="docText">54.24</p></TD><TD class="rightBorder" align="center" valign="top"><p class="docText">73.24</p></td><td class="rightBorder" align="center" valign="top"><p class="docText">19.13</p></TD><td class="rightBorder" align="center" valign="top"><p class="docText">51.70</P></td><TD class="rightBorder" align="center" valign="top"><p class="docText">70.87</p></td><td class="rightBorder" align="center" valign="top"><p class="docText">2.37</p></td><td class="rightBorder" align="center" valign="top"><p class="docText">20.62</p></td><td class="rightBorder" align="center" valign="top"><p class="docText">84.98</p></td><td class="rightBorder" align="center" valign="top"><p class="docText">105.69</p></td><td class="docTableCell" align="center" valign="top"><p class="docText">64</p></td></TR><TR><td class="rightBorder" align="center" valign="top"><p class="docText">12</P></TD><TD class="rightBorder" align="center" valign="top"><p class="docText">22.92</p></TD><TD class="rightBorder" align="center" valign="top"><p class="docText">63.54</P></td><TD class="rightBorder" align="center" valign="top"><p class="docText">86.51</p></TD><TD class="rightBorder" align="center" valign="top"><p class="docText">22.94</P></td><TD class="rightBorder" align="center" valign="top"><p class="docText">61.28</P></td><TD class="rightBorder" align="center" valign="top"><p class="docText">84.29</P></td><td class="rightBorder" align="center" valign="top"><p class="docText">2.22</p></td><TD class="rightBorder" align="center" valign="top"><p class="docText">24.41</p></TD><td class="rightBorder" align="center" valign="top"><p class="docText">101.68</P></td><td class="rightBorder" align="center" valign="top"><p class="docText">126.20</p></td><td class="docTableCell" align="center" valign="top"><p class="docText">66</p></td></tr></table></p><br>
<p class="docText">All times are in seconds and are the total for the parent and all its children. There are many items to consider from this data.</p>
<p class="docText">The eighth column, labeled &quot;<font face="symbol">D</font> clock,&quot; is the difference in seconds between the clock times from advisory coarse-grained locking to advisory fine-grained locking. This is the measurement of how much concurrency we obtain by going from coarse-grained locking to fine-grained locking. On the system used for these tests, coarse-grained locking is roughly the same until we have more than seven processes. Even after seven processes, the decrease in clock time using fine-grained locking isn't that great (less than 3 percent), which makes us wonder whether the additional code required to implement fine-grained locking is worth the effort.</p>
<p class="docText">We would like the clock time to decrease from coarse-grained to fine-grained locking, as it eventually does, but we expect the system time to remain higher for fine-grained locking, for any number of processes. The reason we expect this is that with fine-grained locking, we are issuing more <tt>fcntl</tt> calls than with coarse-grained locking. If we total the number of <tt>fcntl</tt> calls in <a class="docLink" href="#ch20fig06">Figure 20.6</a> for coarse-grained locking and fine-grained locking, we have an average of 21,730 for coarse-grained locking and 25,292 for fine-grained locking. (To get these numbers, realize that each operation in <a class="docLink" href="#ch20fig06">Figure 20.6</a> requires two calls to <tt>fcntl</tt> for coarse-grained locking and that the first three calls to <tt>db_store</tt> along with record deletion [record found] each require four calls to <tt>fcntl</tt> for fine-grained locking.) We expect this increase of 16 percent in the number of calls to <tt>fcntl</tt> to result in an increased system time for fine-grained locking. Therefore, the slight decrease in system time for fine-grained locking, when the number of processes exceeds seven, is puzzling.</p>
<p class="docText">The reason for the decrease is that with coarse-grained locking, we hold locks for longer periods of time, thus increasing the likelihood that other processes will block on a lock. With fine-grained locking, the locking is done over shorter intervals, so there is less chance that processes will block. If we analyze the system behavior running 12 database processes, we will see that there is three times as much process switching with coarse-grained locking as with fine-grained locking. This means that processes block on locks less often with fine-grained locking.</p>
<p class="docText">The final column, labeled &quot;<font face="symbol">D</font> percent,&quot; is the percentage increase in the system CPU time from advisory fine-grained locking to mandatory fine-grained locking. These percentages verify what we saw in <a class="docLink" href="#ch20fig07">Figure 20.7</a>, that mandatory locking adds significantly (between 33 percent and 66 percent) to the system time.</p>
<p class="docText">Since the user code for all these tests is almost identical (there are some additional <tt>fcntl</tt> calls for both advisory fine-grained and mandatory fine-grained locking), we expect the user CPU times to be the same across any row.</p>
<p class="docText">The values in the first row of <a class="docLink" href="#ch20fig08">Figure 20.8</a> are similar to those for an <span class="docEmphasis">nrec</span> of 500 in <a class="docLink" href="#ch20fig07">Figure 20.7</a>. This corresponds to our expectation.</p>
<p class="docText"><a class="docLink" href="#ch20fig09">Figure 20.9</a> is a graph of the data from <a class="docLink" href="#ch20fig08">Figure 20.8</a> for advisory fine-grained locking. We plot the clock time as the number of processes goes from 1 to 12. We also plot the user CPU time divided by the number of processes and the system CPU time divided by the number of processes.</P>
<a name="ch20fig09"></a><P><center>
<h5 class="docFigureTitle">Figure 20.9. Values from <a class="docLink" href="#ch20fig08">Figure 20.8</a> for advisory fine-grained locking</H5>
<p class="docText"><div class="v1"><a target="_self" href="images/0201433079/graphics/20fig09_alt.gif;423615">[View full size image]</a></div><img border="0" alt="" id="195131139046" width="500" height="329" SRC="images/0201433079/graphics/20fig09.gif;423615"></P>
</center></P><br>
<p class="docText"><a name="idd1e153958"></a><a name="idd1e153963"></a><a name="idd1e153968"></a><a name="idd1e153973"></a><a name="idd1e153978"></a><a name="idd1e153983"></a><a name="idd1e153988"></a><a name="idd1e153993"></a><a name="idd1e153998"></a><a name="idd1e154003"></a><a name="idd1e154006"></a>Note that both CPU times, divided by the number of processes, are linear but that the plot of the clock time is nonlinear. The probable reason is the added amount of CPU time used by the operating system to switch between processes as the number of processes increases. This operating system overhead would show up as an increased clock time, but shouldn't affect the CPU times of the individual processes.</P>
<p class="docText">The reason the user CPU time increases with the number of processes is that there are more records in the database. Each hash chain is getting longer, so it takes the <tt>_db_find_and_lock</tt> function longer, on the average, to find a record.</P>


<UL></ul></TD></tr></table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr><td><div STYLE="MARGIN-LEFT: 0.15in;"><a href="toc.html"><img src="images/team.gif" width="60" height="17" border="0" align="absmiddle"  alt="Team BBL"></a></div></td>
<td align="right"><div STYLE="MARGIN-LEFT: 0.15in;">
<a href=ch20lev1sec8.html><img src="images/prev.gif" width="60" height="17" border="0" align="absmiddle" alt="Previous Page"></a>
<a href=ch20lev1sec10.html><img src="images/next.gif" width="60" height="17" border="0" align="absmiddle" alt="Next Page"></a>
</div></td></tr></table>
</body></html><br>
<table width="100%" cellspacing="0" cellpadding="0"
style="margin-top: 0pt; border-collapse: collapse;"> 
<tr> <td align="right" style="background-color=white; border-top: 1px solid gray;"> 
<a href="http://www.zipghost.com/" target="_blank" style="font-family: Tahoma, Verdana;
 font-size: 11px; text-decoration: none;">The CHM file was converted to HTM by Trial version of <b>ChmD<!--179-->ecompiler</b>.</a>
</TD>
</TR><tr>
<td align="right" style="background-color=white; "> 
<a href="http://www.etextwizard.com/download/cd/cdsetup.exe" target="_blank" style="font-family: Tahoma, Verdana;
 font-size: 11px; text-decoration: none;">Download <b>ChmDec<!--179-->ompiler</b> at: http://www.zipghost.com</a>
</TD></tr></table>
